﻿/*********************************************************************************
* Copyright(c)  	2011 ZXHLRJ.COM
 * 创建日期：		2011-12-30 16:07:16 
 * 文 件 名：		controller.cs 
 * CLR 版本: 		2.0.50727.3625 
 * 创 建 人：		黄炳仪
 * 文件版本：		1.0.0.0
 * 修 改 人： 
 * 修改日期： 
 * 备注描述：         
**********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Collections;
using Newtonsoft.Json;

namespace UNMS
{

    public class Person
    {
        public string Number { get; set; }
        public string FullName { get; set; }
        public SimpleObject Simple { get; set; }
    }

    public class SimpleObject
    {
        public string id { get; set; }
        public string text { get; set; }
    }

    public partial class controller : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Hashtable output = new Hashtable();
            string act = Request["act"].ToString().Trim();
            if (!IsPostBack)
            {
                if (act.Equals("check"))
                {
                    string usercode = Request["usercode"].ToString().Trim();
                    output.Add("result", "no");
                    if (usercode.ToLower().Equals("kaleyroy"))
                    {
                        output.Clear();
                        output.Add("result", "ok");
                    }
                    Response.Write(JsonConvert.SerializeObject(output));
                }
                else if (act.Equals("level"))
                {
                    string[] chsLevels = new string[]{"一级会员","二级会员","三级会员","四级会员","五级会员","六级会员","七级会员","八级会员","九级会员","十级会员"}; 
                    StringBuilder sBuilder = new StringBuilder();
                    sBuilder.Append("<div style='background:#fafafa;padding:5px;'>选择级别</div>");
                    for (int i = 1; i <= 10; i++)
                    {
                        string option = string.Format("<label><input type='radio' name='slevel' value='{0}'><span>{1}</span></label>",i,chsLevels[i-1]);
                        sBuilder.Append(option);
                        if (i < 10)
                        {
                            sBuilder.Append("<br>");
                        }
                    }
                    Response.Write(sBuilder.ToString());
                }
                else if (act.Equals("person"))
                {
                    int pageIndex = int.Parse(Request["page"]);
                    int pageSize = int.Parse(Request["rows"]);
                    string query = Request["q"];
                    List<Person> persons = new List<Person>();
                    for (int i = 1; i <= 100; i++)
                    {
                        Person person = new Person()
                        {
                            Number = "100" + i,
                            FullName = "Name " + i
                        };
                        persons.Add(person);
                    }

                    output.Add("total", persons.Count);
                    if (query != null)
                    {
                        output.Add("rows", persons.Where(p => p.FullName.ToLower().Trim().Contains(query)).Skip((pageIndex - 1) * pageSize).Take(pageSize));
                    }
                    else
                    {
                        output.Add("rows", persons.Skip((pageIndex - 1) * pageSize).Take(pageSize));
                    }
                    
                    Response.Write(JsonConvert.SerializeObject(output));
                }
                else if (act.Equals("bank"))
                {
                    List<SimpleObject> banks = new List<SimpleObject>();
                    banks.Add(new SimpleObject() { id = "ABC", text = "中国农业银行" });
                    banks.Add(new SimpleObject() { id = "ICBC", text = "中国工商银行" });
                    banks.Add(new SimpleObject() { id = "CCB", text = "中国建设银行" });
                    banks.Add(new SimpleObject() { id = "BOC", text = "中国银行" });
                    banks.Add(new SimpleObject() { id = "BCM", text = "交通银行" });
                    banks.Add(new SimpleObject() { id = "CMBC", text = "中国民生银行" });
                    banks.Add(new SimpleObject() { id = "CMB", text = "招商银行" });
                    banks.Add(new SimpleObject() { id = "CIB", text = "兴业银行" });
                    banks.Add(new SimpleObject() { id = "CEB", text = "中国光大银行" });

                    //throw new ApplicationException("E");

                    Response.Write(JsonConvert.SerializeObject(banks));
                }
                else if (act.Equals("province"))
                {
                    List<SimpleObject> provinces = new List<SimpleObject>();
                    provinces.Add(new SimpleObject() { id = "BJ", text = "北京市" });
                    provinces.Add(new SimpleObject() { id = "TJ", text = "天津市" });
                    provinces.Add(new SimpleObject() { id = "HB", text = "河北省" });
                    provinces.Add(new SimpleObject() { id = "SX", text = "山西省" });
                    provinces.Add(new SimpleObject() { id = "NMG", text = "内蒙古区" });
                    provinces.Add(new SimpleObject() { id = "LN", text = "辽宁省" });
                    provinces.Add(new SimpleObject() { id = "JL", text = "吉林省" });
                    provinces.Add(new SimpleObject() { id = "HLJ", text = "黑龙江省" });
                    provinces.Add(new SimpleObject() { id = "SH", text = "上海市" });
                    provinces.Add(new SimpleObject() { id = "JS", text = "江苏省" });
                    provinces.Add(new SimpleObject() { id = "ZJ", text = "浙江省" });
                    provinces.Add(new SimpleObject() { id = "AW", text = "安徽省" });
                    provinces.Add(new SimpleObject() { id = "FJ", text = "福建省" });
                    provinces.Add(new SimpleObject() { id = "JX", text = "江西省" });
                    provinces.Add(new SimpleObject() { id = "SD", text = "山东省" });
                    provinces.Add(new SimpleObject() { id = "HN", text = "河南省" });
                    provinces.Add(new SimpleObject() { id = "GX", text = "广西省" });
                    provinces.Add(new SimpleObject() { id = "GD", text = "广东省" });

                    Response.Write(JsonConvert.SerializeObject(provinces));
                }
                
            }
        }
    }
}
